package org.gensokyo.crawler

import java.io.File
import java.text.{DecimalFormat, SimpleDateFormat}

import com.typesafe.scalalogging.slf4j.StrictLogging
import org.apache.commons.io.FileUtils
import org.apache.poi.ss.usermodel.{Cell, WorkbookFactory}


/**
  * Created by liusen on 17-3-4.
  */
object Start3 extends StrictLogging {

  val path = "~/Download"

  def deal = {
    new File(path).listFiles().toList
      .filter(_.getName.split("\\.").toList.last == "srt")
      //      .slice(0, 1)
      .map(x => {
      val fileName = x.getName
      val shortFileName = x.getName.replace(".srt", "")
      val outputFileName = s"${shortFileName}.txt"
      val text = io.Source.fromFile(x).getLines().toList.mkString("\n")
      val outText = text.replaceAll("[0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3} --> [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}", "")
        .replaceAll("\n[0-9]+\n", " ")
        .replaceAll("\n", " ")
        .replaceAll("  ", " ")
        .replaceAll("  ", " ")
        .replaceAll("  ", " ")
        .replaceAll("  ", " ")
      scala.tools.nsc.io.File(s"${path}/${outputFileName}").writeAll(outText)
    })
  }

  def main(args: Array[String]) {
    deal
  }
}
